﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.ShipMethod
{
    public class ShipMethodPresenter : Presenter<IShipMethodView>
    {
        public ShipMethodPresenter(IShipMethodView view)
            : base(view)
        {
        }

        public void Display(string shipMethodId)
        {
            if (shipMethodId == null) return;

            var shipMethod = Model.GetShipMethod(shipMethodId);

            View.ShipMethodID = shipMethod.ShipMethodID;
            View.ShipName = shipMethod.ShipName;
            View.ShipCode = shipMethod.ShipCode;
            View.Description = shipMethod.Description;
            View.IsActive = shipMethod.IsActive;
        }

        public int Save()
        {
            var shipMethod = new ShipMethodModel
            {
                ShipMethodID = View.ShipMethodID,
                ShipName = View.ShipName,
                ShipCode = View.ShipCode,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (View.ShipMethodID == null)
                return Model.AddShipMethod(shipMethod);
            else
                return Model.UpdateShipMethod(shipMethod);
        }

        public int Delete(string shipMethodId)
        {
            return Model.DeleteShipMethod(shipMethodId);
        }
    }
}
